
$(document).ready(function(){
	//findAllPmsnByRoleId();
	$('#currentRole').text(getCookie(RName));
	findAllPermission();
});

function findAllPermission(){	
	var timestamp = Date.parse(new Date());
	$.get("admin/Role_findAllPermission.action?ts="+timestamp,null,findAllPermissionRst);
}

function findAllPermissionRst(data){
	//alert("ffffffff");
	//alert(getCookie(RId));
	//alert(data.ajaxRst);
	$.each(data.permissions,function(i,n){
		//fillDatatoHTML(n.PId,n.PName,n.tbPlanGrade.pgName,n.tbPlanStatus.pstName,n.tbPlanType.ptName);
		var pmsnID=n.PId;
		var idx=pmsnID.indexOf('0');		
		if(idx==1){
			var strHtml="";
			strHtml+="<li id=";
			strHtml+=pmsnID;
			strHtml+="><input type='checkbox' /><label>";
			strHtml+=n.PName;
			strHtml+="</label><ul></ul></li>";
			$('#rolePmsnTree').append(strHtml);
		}else{
			var prefix=pmsnID.substring(0,idx-1);
			var subfix=pmsnID.substring(idx,pmsnID.length);
			var parentNode=prefix+"0"+subfix;
			var strHtml="";
			strHtml+="<li id=";
			strHtml+=pmsnID;
			strHtml+="><input type='checkbox' /><label>";
			strHtml+=n.PName;
			strHtml+="</label></li>";
			$("#"+parentNode+" ul").append(strHtml);
		}
		
		//alert(prefix+"0"+subfix);
		
		//alert(n.PName+"："+prefix);
		
		//alert(Math.round(parseInt(pmsnID)/2));		
		//alert(pmsnID.replace("0",""));
		//alert(pmsnID.subString)
		
		//alert(n.PId.indexOf('0'));
		//alert(n.PName);
	});
	$("ul.tree").checkTree({
		
});
	//$("ul.tree").checkTree();
	//alert($('#1000').html());
	//alter($('#rolePmsnTree').html());
}

function findAllPmsnByRoleId(){	
	var timestamp = Date.parse(new Date());
	//$.get("admin/Role_findAllPmsnByRoleId.action?ts="+timestamp+"&RId="+getCookie(RId),null,findAllPmsnByRoleIdRst);
	$.get("admin/Role_findAllPermission.action?ts="+timestamp,null,findAllPmsnByRoleIdRst);
}

function findAllPmsnByRoleIdRst(data){
	alert("ffffffff");
	alert(getCookie(RId));
	alert(data.ajaxRst);
}